<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>获取数据</title>
</head>
<body>

</body>
<script>
	// 如果数据不存在：通过getItem获取到 的值是null,其它的是undefined.
	// console.log(localStorage.userName);
	// console.log(localStorage["userName"]);
	// console.log(localStorage.getItem("userName"));// 建议使用
	//
	// console.log(localStorage.age);
	// console.log(localStorage["age"]);
	// console.log(localStorage.getItem("age"));
	//
	// console.log(localStorage.sex);
	// console.log(localStorage["sex"]);
	// console.log(localStorage.getItem("sex"));
	
	
	// console.log(localStorage.length);// 存储Storage的数量
	
	
	// 遍历
	// for(let key in localStorage){
	// 	console.log(key);
	// }
	
	for(let index = 0;index<localStorage.length;index++){
		// console.log(index);
		let key  = localStorage.key(index);
		console.log(key,localStorage.getItem(key))
	}
</script>
</html>